package com.example.jsondemo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean;

/**
 * @author Keson
 * @version 1.0
 * @description: TODO 更换数据源配置
 * @date 2021/9/15 11:46
 */
@Configuration
public class RepositoryConfig {

    @Value("${rules.datasource}")
    private String ruleDefinitionFilePath;

    @Bean
    public Jackson2RepositoryPopulatorFactoryBean getRepository(){
        Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean();
        factoryBean.setResources( new Resource [] { new ClassPathResource(ruleDefinitionFilePath) } );
        return factoryBean;
    }
}
